//
//  HeadImgSetViewController.m
//  iOS-CtrlV
//
//  Created by 龚 杰 on 12-12-21.
//  Copyright (c) 2012年 Wang Li. All rights reserved.
//

#import "HeadImgSetViewController.h"

@interface HeadImgSetViewController ()

@end

@implementation HeadImgSetViewController

//- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
//{
//    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
//    if (self) {
//        // Custom initialization
//    }
//    return self;
//}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    if([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
        [self.navigationController.navigationBar setBackgroundImage:tAppDel.m_MidNavImg forBarMetrics: UIBarMetricsDefault];
        self.navigationController.navigationBar.clipsToBounds = NO;
        
//        UIImageView* tImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navshadow.png"]];
//        tImgView.frame =CGRectMake(0, 44, 320, 5);
//        [self.navigationController.navigationBar addSubview:tImgView];
//        [tImgView release];
    }
    m_CloseBttBarItem =[UIButton buttonWithType:UIButtonTypeCustom];
    m_CloseBttBarItem.frame =CGRectMake(self.navigationController.navigationBar.frame.size.width-44, 0, 44, 44);
    [m_CloseBttBarItem setImage:[UIImage imageNamed:@"navclose.png"] forState:UIControlStateNormal];
    [m_CloseBttBarItem addTarget:self action:@selector(navCloseBttBar) forControlEvents:UIControlEventTouchUpInside];
    [m_CloseBttBarItem retain];
    [self.navigationController.navigationBar addSubview:m_CloseBttBarItem];
    
    m_headTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)
                                               style:UITableViewStylePlain];
    [m_headTableView setDataSource:self];
    [m_headTableView setDelegate:self];
    [m_headTableView setBackgroundColor:[UIColor whiteColor]];
//    m_headTableView.separatorColor = [UIColor clearColor];
    [self.view addSubview:m_headTableView];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [m_CloseBttBarItem removeFromSuperview];
}

- (void)navCloseBttBar
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)changeButton:(UIButton*)ibutton
{
    NSLog(@"tag%d",ibutton.tag);
}

#pragma mark -
#pragma mark UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
#pragma mark UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString* tSStrCell = @"FansAndAttentioncell";
    UITableViewCell* tCell = [tableView dequeueReusableCellWithIdentifier:tSStrCell];
    if (tCell == nil) {
        tCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tSStrCell] autorelease];
        tCell.selectionStyle = UITableViewCellSelectionStyleNone;
        for (int i = 0; i < 4; ++i) {
            UIButton* ibutton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            ibutton.frame = CGRectMake(16+16*i+60*i, 10, 60, 60);
            ibutton.tag = 100+i;
            [ibutton addTarget:self action:@selector(changeButton:) forControlEvents:UIControlEventTouchUpInside];
            [tCell.contentView addSubview:ibutton];
        }

    }

    for (int i = 0; i < 4; ++i) {
        UIButton* ibutton = (UIButton*)[tCell viewWithTag:100+i];
        ibutton.tag = i+indexPath.row*4;
    }

    return tCell;
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)dealloc
{
    [m_CloseBttBarItem release];
    [super dealloc];
}
@end
